namespace app\index\controller;

use core\Controller;

class Index extends Controller
{
    public  function upload(Request $request){
        if($request->isPost()){
            $post = $request->post();
            $filedata = $post['img'];
            $fileType = $post['type'];
            if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $filedata, $result)){
                $type = $result[2]; //jpeg

                //去除图片类型
                $img = base64_decode(str_replace($result[1], '', $filedata)); //返回文件流
            }

            $re = file_put_contents('./xxx.'.strtotime('now').microtime().'.'.$type,$img);

            return $this->json(['code'=>1,'data'=>$request,'msc'=>'success']);
        }
        return $this->view('');
    }
}